/*
 * XXX
 */
package edu.uhcl.csci4838.group3.view;

import edu.uhcl.csci4838.group3.R;
import edu.uhcl.csci4838.group3.contentstorage.DefaultFileManager;
import edu.uhcl.csci4838.group3.database.BackpackEduDatabaseHelper;
import edu.uhcl.csci4838.group3.database.BackpackEduDatabaseHelper.CursorCourse;
import edu.uhcl.csci4838.group3.database.info.Course;
import edu.uhcl.csci4838.group3.database.info.Task;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

/**
 * XXX
 * 
 * @author XXX
 *
 */
public class NoteActivity extends Activity {
	
	/**
	 * The database helper object.
	 */
	private static BackpackEduDatabaseHelper dbHelper;
	
	/**
	 * The file manager.
	 */
	private static DefaultFileManager manager;
	
	/**
	 * XXX
	 * 
	 * @param savedInstanceState
	 */
	/* 
	 * (non-Javadoc)
	 * 
	 * @see android.app.ActivityGroup#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		this.setContentView(R.layout.note_item);
		
		// Calling intent
		final Intent callingIntent = this.getIntent();
		final long courseId = callingIntent.getLongExtra(this.getString(R.string.intent_extra_courseId),
				-1);
		final String fileName = callingIntent.getStringExtra(this.getString(R.string.intent_extra_fileName));
		
		// Cursor
		dbHelper = new BackpackEduDatabaseHelper(this);
		ContentValues criteria = new ContentValues();
		criteria.put(Course.ID,
				Long.valueOf(courseId));
		CursorCourse courseCursor = dbHelper.getCourse(criteria,
				null,
				true);
		this.startManagingCursor(courseCursor);
		
		manager = new DefaultFileManager(getApplicationContext(), courseCursor.getColSemesterName(), courseCursor.getColName(), fileName);
		
		
	}
	
	public void save(View view) {
		EditText txtTitle = (EditText) findViewById(R.id.txt_Title);
		EditText txtNote = (EditText) findViewById(R.id.txt_Note);
		manager.setFileName(txtTitle.getText().toString());
		manager.writeToFIle(txtNote.getText().toString());
		this.finish();
	}
	
	/**
	 * XXX
	 * 
	 * @param view
	 *            XXX
	 */
	public void cancel(final View view) {
		this.finish();
	}
	
	
}
